﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CSharpDevTools.Core;
using HandyControl.Controls;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDevTools.ViewModels
{
    internal class DESControlViewModel : EncryptBaseViewModel
    {
        private string key;

        /// <summary>
        /// 密钥
        /// </summary>
        public string Key
        {
            get => this.key;
            set => this.SetProperty(ref this.key, value);
        }

        protected override void Encrypt()
        {
            if (string.IsNullOrEmpty(this.OriginalData))
            {
                MessageBox.Error("原始数据不能为空！", "错误");
                return;
            }

            if (string.IsNullOrEmpty(this.Key))
            {
                MessageBox.Error("密钥不能为空！", "错误");
                return;
            }

            this.EncryptedData = DESEncrypt.Encrypt(this.OriginalData, this.Key);
        }

        protected override void Decrypt()
        {
            if (string.IsNullOrEmpty(this.EncryptedData))
            {
                MessageBox.Error("加密后数据不能为空！", "错误");
                return;
            }

            if (string.IsNullOrEmpty(this.Key))
            {
                MessageBox.Error("密钥不能为空！", "错误");
                return;
            }

            this.OriginalData = DESEncrypt.Decrypt(this.EncryptedData, this.Key);
        }
    }
}
